package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// com.atguigu.spzx.manager.controller
@RestController
@Tag(name = "品牌管理")
@RequestMapping(value="/admin/product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService ;



    //根据第三季分类查询品牌列表
    @Operation(summary = "根据第三季分类查询品牌列表")
    @GetMapping("findByCategory3Id/{category3Id}")
    public Result findByCategory3Id(@PathVariable Long category3Id){
        List<Brand> list = brandService.findByCategory3Id(category3Id);
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }


    //获取全部品牌
    @Operation(summary = "获取全部品牌")
    @GetMapping("findAllBrand")
    public Result findAllBrand(){
        List<Brand> list = brandService.findAll();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    //分页查询
    @Operation(summary = "分页查询")
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<Brand>> findByPage(@PathVariable Integer page, @PathVariable Integer limit) {
        PageInfo<Brand> pageInfo = brandService.findByPage(page, limit);
        return Result.build(pageInfo , ResultCodeEnum.SUCCESS) ;
    }

    // com.atguigu.spzx.manager.controller
    //插入数据
    @Operation(summary = "插入品牌")
    @PostMapping("save")
    public Result save(@RequestBody Brand brand) {
        brandService.save(brand);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    //修改品牌名称和logo
    @Operation(summary = "修改品牌和logo")
    @PutMapping("edit")
    public Result edit(@RequestBody Brand brand){
        brandService.edit(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "根据名称删除数据")
    @GetMapping("cancel/{id}")
    public Result cancel(@PathVariable Integer id){
        brandService.deletByName(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

}